(function () {
    "use strict";

    angular.module('core').factory('etiquetaService', factory);
    factory.$inject = ['$http', '$q'];

    function factory($http, $q) {

        var _get = function (id) {
            var deferred = $q.defer();
            $http.post('/etiqueta/get', id)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _getAll = function (args) {
            var deferred = $q.defer();
            $http.post('/etiqueta/getall', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _getImpressoras = function (args) {
            var deferred = $q.defer();
            $http.post('/etiqueta/getimpressoras', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _getProdutos = function (args) {
            var deferred = $q.defer();
            $http.post('/etiqueta/getprodutos', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _count = function (args) {
            var deferred = $q.defer();
            $http.post('/etiqueta/count', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        var _save = function (item) {
            var deferred = $q.defer();
            $http.post('/etiqueta/save', item)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _delete = function (id) {
            var deferred = $q.defer();
            var args = { id: id }
            $http.post('/etiqueta/delete', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        return {
            get: _get,
            getProdutos: _getProdutos,
            getAll: _getAll,
            count: _count,
            save: _save,
            delete: _delete,
            getImpressoras: _getImpressoras
        };
    }

})();


